import Vue from "vue";
import Router from "vue-router";

Vue.use(Router);
/**
 * 异步模块获取，打包的时候每次访问这个路由的时候会单调单个文件，按需加载。
 * component: resolve => require(["../components/common/Home.vue"], resolve),
 */
export default new Router({
  mode: "history",
  routes: [
    {
      path: "/",
      redirect: "/dashboard"
    },
    {
      path: "/",
      component: resolve => require(["../components/common/Home.vue"], resolve),
      meta: { title: "自述文件" },
      children: [
        {
          path: "/dashboard",
          component: resolve =>
            require(["../components/page/Dashboard.vue"], resolve),
          meta: { title: "系统首页" }
        },
        {
          path: "/order",
          component: resolve =>
            require(["../components/page/sysmanager/order.vue"], resolve),
          meta: { title: "订单管理" }
        },
        {
          path: "/vip",
          component: resolve =>
            require(["../components/page/sysmanager/vip.vue"], resolve),
          meta: { title: "会员管理" }
        },
        {
          path: "/ware",
          component: resolve =>
            require(["../components/page/sysmanager/ware.vue"], resolve),
          meta: { title: "库存管理" }
        },
        {
          path: "/sale",
          component: resolve =>
            require(["../components/page/sysmanager/sale.vue"], resolve),
          meta: { title: "促销活动管理" }
        },
        {
          path: "/goods",
          component: resolve =>
            require(["../components/page/sysmanager/goods.vue"], resolve),
          meta: { title: "商品管理" }
        },
        {
          // 权限页面
          path: "/permission",
          component: resolve =>
            require(["../components/page/Permission.vue"], resolve),
          meta: { title: "权限测试", permission: true }
        },
        {
          path: "/404",
          component: resolve =>
            require(["../components/page/404.vue"], resolve),
          meta: { title: "404" }
        },
        {
          path: "/403",
          component: resolve =>
            require(["../components/page/403.vue"], resolve),
          meta: { title: "403" }
        },
        {
          path: "/admin",
          component: resolve =>
            require(["../components/page/admin.vue"], resolve),
          meta: { title: "用户信息" }
        }
      ]
    },
    {
      path: "/",
      component: resolve => require(["../components/page/Login.vue"], resolve)
    },
    {
      path: "*",
      redirect: "/404"
    }
  ]
});
